(function() {
var i, text, code, codes = document.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
  code = codes[i];
  if (code.parentNode.tagName !== 'PRE' &&
      code.childElementCount === 0) {
    text = code.textContent;
    if (/^\\\((.|\s)+\\\)$/.test(text) ||
        /^\$(.|\s)+\$$/.test(text) ||
        /^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
      code.outerHTML = code.innerHTML;  // remove <code></code>
      continue;
    }
  }
  i++;
}
})();